package cn.maihe.elg.operation.centers.guogu.channel.service;

import cn.maihe.elg.operation.centers.guogu.channel.GuoGuBaseChannelService;
import cn.maihe.elg.operation.centers.guogu.dto.channel.req.GuoGuCusQueryReq;
import cn.maihe.elg.operation.centers.guogu.dto.channel.resp.GuoGuCusQueryResp;
import cn.maihe.elg.operation.centers.guogu.dto.channel.resp.GuoGuCusQueryRespData;
import cn.maihe.elg.operation.centers.guogu.enums.GuoGuChannelMethod;
import cn.maihe.elg.operation.centers.guogu.enums.GuoGuRespCodeEnum;
import cn.maihe.elg.operation.model.dto.InnerBaseResp;
import cn.maihe.elg.operation.model.enums.CenterNoEnum;
import cn.maihe.elg.operation.service.business.BidCustomerService;
import cn.maihe.elg.operation.service.order.AcceptOrderInfoService;
import cn.maihe.elg.operation.supports.system.ElgResourceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description 客户资料查询
 * @Author SSX
 * @Date 2025/03/17
 */
@Service
@Slf4j
public class GuoGuCusQueryChannelService extends GuoGuBaseChannelService<GuoGuCusQueryReq, GuoGuCusQueryResp> {

    @Resource
    private ElgResourceService elgResourceService;
    @Resource
    private AcceptOrderInfoService acceptOrderInfoService;
    @Resource
    private BidCustomerService bidCustomerService;

    @Override
    protected GuoGuChannelMethod methodEnum() {
        return GuoGuChannelMethod.cus_query;
    }


    public InnerBaseResp<GuoGuCusQueryRespData> queryCusInfo(String clientId,CenterNoEnum centerNoEnum, String applyno) {
        GuoGuCusQueryReq guoGuCusInfoReqDTO = new GuoGuCusQueryReq();
        guoGuCusInfoReqDTO.setTradeNo(applyno);
        InnerBaseResp<GuoGuCusQueryRespData> innerBaseResp;
        GuoGuCusQueryResp chlBizRespData;
        try {
            chlBizRespData = this.doRequest(clientId,centerNoEnum, guoGuCusInfoReqDTO);
            //code=10已回调成功作为成功处理 {"code":"10","message":"该保函已经成功回调过了"}
            if (GuoGuRespCodeEnum.isSuccess(chlBizRespData.getCode())) {
                innerBaseResp = InnerBaseResp.success(chlBizRespData.getData());
            } else {
                innerBaseResp = InnerBaseResp.error(chlBizRespData.getMsg());
            }
        } catch (Exception e) {
            log.error("查询客户信息 >> [{}] 异常:{}", centerNoEnum.getCenterName(), e.getMessage(), e);
            innerBaseResp = InnerBaseResp.error("查询客户信息异常:" + e.getMessage());
        }

        return innerBaseResp;

    }
}
